package com.yanti.controller;

import com.yanti.domain.ResponseResult;
import com.yanti.domain.dto.PostgraduateRequestDTO;
import com.yanti.domain.enums.AppHttpCodeEnum;
import com.yanti.repository.ChatHistoryRepository;
import com.yanti.service.impl.PostgraduateAssistantService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequiredArgsConstructor
@RequestMapping("/postgraduate")
public class PostgraduateController {
    private final PostgraduateAssistantService assistantService;


    @PostMapping("/assist")
    public Mono<ResponseEntity<ResponseResult>> assist(
        @RequestBody PostgraduateRequestDTO request) {
        return assistantService.handleRequest(request)
            .map(response -> ResponseEntity.ok(ResponseResult.okResult(response)))
            .onErrorResume(e -> Mono.just(
                ResponseEntity.ok(ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR))
            ));
    }
    @PostMapping("/analysis")
    public Mono<ResponseEntity<ResponseResult>> analysis(
            @RequestBody PostgraduateRequestDTO request){
        return assistantService.analysisWrongQuestion(request)
                .map(response -> ResponseEntity.ok(ResponseResult.okResult(response)))
                .onErrorResume(e -> Mono.just(
                        ResponseEntity.ok(ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR))
                ));
    }
}